<template>
  <div class="productlist">
    <van-nav-bar
      :title="$route.query.tname"
      left-text="返回"
      right-text="我的"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />

    <van-card
      v-for="(item, index) in list"
      :tag="index < 8 ? '热卖' : ''"
      :key="item.id"
      :num="item.amount"
      :price="item.price.toFixed(2)"
      :origin-price="(item.price * 1.3).toFixed(2)"
      :title="item.name"
      :thumb="item.coverImage | dalImg"
      @click="toDetail(item.id)"
    >
    </van-card>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    async loadData() {
      const res = await axios.get("http://localhost:1337/api/v1/products", {
        params: { category: this.$route.query.tid },
      });
      this.list.push(...res.data.data);
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {
      this.$router.push({
        name: "User",
      });
    },
    toDetail(id) {
      this.$router.push({
        name: "Detail",
        query: {
          id,
        },
      });
    },
  },
};
</script>

<style></style>
